/*     */ package org.flashzlm.tools.ui;
/*     */ 
/*     */ import java.awt.BorderLayout;
/*     */ import java.awt.FlowLayout;
/*     */ import java.awt.GridBagConstraints;
/*     */ import java.awt.GridBagLayout;
/*     */ import java.awt.Insets;
/*     */ import java.awt.event.ActionEvent;
/*     */ import java.awt.event.ActionListener;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import javax.swing.JButton;
/*     */ import javax.swing.JComboBox;
/*     */ import javax.swing.JPanel;
/*     */ import javax.swing.JProgressBar;
/*     */ import javax.swing.JTextField;
/*     */ import javax.swing.Timer;
/*     */ import org.flashzlm.tools.QiYao;
/*     */ import org.flashzlm.tools.analysis.Gua;
import org.flashzlm.tools.analysis.Gua.TiYongGuanXi;
/*     */ import org.flashzlm.tools.shifa.impl.DaYanFa;
import org.flashzlm.tools.shifa.impl.JinQianGua;
/*     */ 
/*     */ public class QiGua extends JPanel
/*     */ {
	/**
	 * 
	 */
	private static final long serialVersionUID = 2046817867082768095L;
	/**
	 * 
	 */

	/*     */   private QiYao qiYao;
	/*     */   private Timer timer;
	/*  33 */   private JTextField jf1 = new JTextField(22);
	/*  34 */   private JTextField jf2 = new JTextField(22);
	/*  35 */   private JTextField jf3 = new JTextField(30);
	            private JTextField jf4 = new JTextField(22);
	/*  36 */   private JComboBox shiFas = new JComboBox();
	/*  37 */   private JComboBox rapids = new JComboBox();
	/*  38 */   private GuaShape guaShape = new GuaShape();
	/*     */ 
	/*  42 */   private JButton btOK = new JButton("Start!");
	/*  43 */   private JButton btCancel = new JButton("Stop!");
	/*     */   private Thread calc;
	/*     */ 
	/*     */   public Map<String, String> analysis(List<Integer> sixYaos)
	/*     */     throws InterruptedException
	/*     */   {
		/*  47 */     Gua gua = new Gua();
		/*  48 */     int guaValue = gua.guaValue(sixYaos);
		/*  49 */     String guaName = Gua.guaValueMap.get(Integer.valueOf(guaValue));
		/*  50 */     int dongYao = gua.duanDongYao(sixYaos);
		/*  51 */     String duan = gua.duanGua(sixYaos, dongYao);
		              TiYongGuanXi tygx=gua.duanTiYong(sixYaos);
		
		/*  52 */     int bianGv = gua.bianGuaValue(sixYaos);
		/*  53 */     String bianGn = Gua.guaValueMap.get(Integer.valueOf(bianGv));
		/*  54 */     int cuoGv = Gua.cuoGuaValue(sixYaos);
		/*  55 */     String cuoGn = Gua.guaValueMap.get(Integer.valueOf(cuoGv));
		/*  56 */     int zongGv = Gua.zongGuaValue(sixYaos);
		/*  57 */     String zongGn = Gua.guaValueMap.get(Integer.valueOf(zongGv));
		/*  58 */     int jiaoHuGv = Gua.jiaoHuGuaValue(sixYaos);
		/*  59 */     String jiaoHuGn = Gua.guaValueMap.get(Integer.valueOf(jiaoHuGv));
		/*     */ 
		/*  61 */     Map<String,String> result = new HashMap<String,String>();
		/*  62 */     result.put("guaName", guaName);
		/*  63 */     result.put("dongYao", String.valueOf(dongYao));
		/*  64 */     result.put("duan", duan);
					  result.put("tiYongShuo", gua.transTiYong(tygx));	
		/*  65 */     result.put("guaValue", String.valueOf(guaValue));
		/*  66 */     result.put("bianGuaName", bianGn);
		/*  67 */     result.put("bianGuaValue", String.valueOf(bianGv));
		/*  68 */     result.put("cuoGuaName", cuoGn);
		/*  69 */     result.put("cuoGuaValue", String.valueOf(cuoGv));
		/*  70 */     result.put("zongGuaName", zongGn);
		/*  71 */     result.put("zongGuaValue", String.valueOf(zongGv));
		/*  72 */     result.put("jiaoHuGuaName", jiaoHuGn);
		/*  73 */     result.put("jiaoHuGuaValue", String.valueOf(jiaoHuGv));
		/*     */ 
		/*  75 */     return result;
	/*     */   }
	/*     */ 
	/*     */   public QiGua()
	/*     */   {
		/*  80 */     final JProgressBar bar = new JProgressBar(0, 6);
		/*  81 */     bar.setStringPainted(true);
		/*  82 */     bar.setString("可以开始卜卦！");
		/*  83 */     int internal = 500;
		/*  84 */     switch (this.rapids.getSelectedIndex())
		/*     */     {
		/*     */     case 0:
			/*  85 */       internal = 750; break;
		/*     */     case 1:
			/*  86 */       internal = 500; break;
		/*     */     case 2:
			/*  87 */       internal = 100;
		/*     */     }
		/*     */ 
		/*  90 */     this.timer = new Timer(internal, new ActionListener()
		/*     */     {
			/*     */       @Override
			public void actionPerformed(ActionEvent e)
			/*     */       {
				/*  94 */         int current = QiGua.this.qiYao.getCurrent();
				/*  95 */         bar.setValue(current);
				/*  96 */         String text = "";
				/*  97 */         if (current == 0) {
					/*  98 */           text = "可以开始卜卦！";
				/*  99 */         } else if (current == 7) {
					/* 100 */           QiGua.this.timer.stop();
					/* 101 */           text = "卜卦完成 ！";
					/* 102 */           QiGua.this.btOK.setEnabled(true);
					/* 103 */           QiGua.this.btCancel.setEnabled(false);
					/* 104 */           List<Integer> sixYaos = QiGua.this.qiYao.getSixYaos();
					/* 105 */           QiGua.this.guaShape.setSixYaos(sixYaos);
					/*     */           try {
						/* 107 */             Map<String,String> result = QiGua.this.analysis(sixYaos);
						/* 108 */             QiGua.this.guaShape.setDongYao(Integer.valueOf(result.get("dongYao")).intValue());
						/* 109 */             QiGua.this.guaShape.repaint();
						/* 110 */             QiGua.this.jf1.setText((result.get("guaName")) + "(卦值为" + (result.get("guaValue")) + "): " + (result.get("duan")));
						/* 111 */             QiGua.this.jf2.setText("变卦(卦值为" + (result.get("bianGuaValue")) + "): " + (result.get("bianGuaName")));
						/* 112 */             QiGua.this.jf3.setText("       错卦: " + (result.get("cuoGuaName")) + "      综卦: " + (result.get("zongGuaName")) + "     交互卦: " + (result.get("jiaoHuGuaName")));
					/*     */                 QiGua.this.jf4.setText(result.get("tiYongShuo"));
						}
					/*     */           catch (InterruptedException e1) {
						/* 115 */             e1.printStackTrace();
					/*     */           }
				/*     */         }
				/*     */         else {
					/* 119 */           text = "起第" + current + "爻";
				/*     */         }
				/*     */ 
				/* 122 */         bar.setString(text);
			/*     */       }
		/*     */     });
		/* 128 */     setLayout(new BorderLayout());
		/* 129 */     JPanel upPanel = new JPanel();
		/* 130 */     add(upPanel, "North");
		/* 131 */     JPanel midPanel = new JPanel();
		/* 132 */     add(midPanel, "Center");
		/* 133 */     JPanel downPanel = new JPanel();
		/* 134 */     add(downPanel, "South");
		/*     */ 
		/* 136 */     FlowLayout f = new FlowLayout();
		/* 137 */     f.setAlignment(1);
		/* 138 */     f.setHgap(60);
		/* 139 */     midPanel.setLayout(f);
		/* 140 */     this.shiFas.addItem("金钱卦");
		/* 141 */     this.shiFas.addItem("大衍之数");
		/* 142 */     midPanel.add(this.shiFas);
		/*     */ 
		/* 144 */     this.rapids.addItem("慢速");
		/* 145 */     this.rapids.addItem("中速");
		/* 146 */     this.rapids.addItem("快速");
		/* 147 */     this.rapids.setSelectedIndex(2);
		/* 148 */     midPanel.add(this.rapids);
		/*     */ 
		/* 150 */     FlowLayout fl = new FlowLayout();
		/* 151 */     fl.setAlignment(1);
		/* 152 */     fl.setHgap(60);
		/* 153 */     downPanel.setLayout(fl);
		/* 154 */     this.btOK.addActionListener(
				/* 155 */       new ActionListener() {
					/*     */       @Override
					public void actionPerformed(ActionEvent e) {
						/* 157 */         QiGua.this.jf1.setText("");
						/* 158 */         QiGua.this.jf2.setText("");
						/* 159 */         QiGua.this.jf3.setText("");
										  QiGua.this.jf4.setText("");
						/* 160 */         QiGua.this.guaShape.setSixYaos(null);
											guaShape.setCurrYao(0);
											guaShape.setDongYao(0);
						/* 161 */         QiGua.this.guaShape.repaint();
						/* 162 */         QiGua.this.qiYao = new QiYao();
											qiYao.setGuaShape(guaShape);
						/* 163 */         switch (QiGua.this.shiFas.getSelectedIndex())
						/*     */         {
						/*     */         case 0:
							/* 164 */           QiGua.this.qiYao.setShiFa(new JinQianGua()); break;
						/*     */         case 1:
							/* 165 */           QiGua.this.qiYao.setShiFa(new DaYanFa());
						/*     */         }
						/* 167 */         switch (QiGua.this.rapids.getSelectedIndex())
						/*     */         {
						/*     */         case 0:
							/* 168 */           QiGua.this.qiYao.setRapid(1500L); break;
						/*     */         case 1:
							/* 169 */           QiGua.this.qiYao.setRapid(1000L); break;
						/*     */         case 2:
							/* 170 */           QiGua.this.qiYao.setRapid(200L);
						/*     */         }
						/* 172 */         QiGua.this.calc = new Thread(QiGua.this.qiYao);
						/* 173 */         QiGua.this.calc.start();
						/* 174 */         QiGua.this.timer.start();
						/* 175 */         QiGua.this.btOK.setEnabled(false);
						/* 176 */         QiGua.this.btCancel.setEnabled(true);
					/*     */       }
				/*     */     });
		/* 181 */     this.btCancel.setEnabled(false);
		/* 182 */     this.btCancel.addActionListener(new ActionListener()
		/*     */     {
			/*     */       @Override
			public void actionPerformed(ActionEvent e) {
				/* 185 */         QiGua.this.calc.interrupt();
				/* 186 */         QiGua.this.timer.stop();
				/* 187 */         bar.setString("可以开始卜卦！");
				/* 188 */         bar.setValue(0);
				/* 189 */         QiGua.this.btCancel.setEnabled(false);
				/* 190 */         QiGua.this.btOK.setEnabled(true);
			/*     */       }
		/*     */     });
		/* 195 */     downPanel.add(this.btOK);
		/* 196 */     downPanel.add(this.btCancel);
		/*     */ 
		/* 198 */     GridBagLayout gbL = new GridBagLayout();
		/* 199 */     upPanel.setLayout(gbL);
		/* 200 */     GridBagConstraints cons = new GridBagConstraints();
		/* 201 */     cons.weightx = 0.0D;
		/* 202 */     cons.weighty = 0.0D;
		/* 203 */     cons.gridx = 0;
		/* 204 */     cons.gridy = 0;
		/* 205 */     cons.gridwidth = 1;
		/* 206 */     cons.gridheight = 3;
		/* 207 */     cons.insets = new Insets(12, 2, 5, 5);
		/* 208 */     cons.fill = 1;
		/* 209 */     cons.ipadx = 60;
		/* 210 */     cons.ipady = 80;
		/*     */ 
		/* 213 */     upPanel.add(this.guaShape, cons);
		/*     */ 
		/* 215 */     cons = new GridBagConstraints();
		/* 216 */     cons.weightx = 0.0D;
		/* 217 */     cons.weighty = 0.0D;
		/* 218 */     cons.gridx = 1;
		/* 219 */     cons.gridy = 0;
		/* 220 */     cons.gridwidth = 1;
		/* 221 */     cons.gridheight = 1;
		/* 222 */     cons.insets = new Insets(15, 0, 5, 5);
		cons.fill = 2;
		/* 223 */     this.jf1.setEditable(false);
		/* 224 */     upPanel.add(this.jf1, cons);
		/*     */ 
		/* 226 */     cons = new GridBagConstraints();
		/* 227 */     cons.weightx = 0.0D;
		/* 228 */     cons.weighty = 0.0D;
		/* 229 */     cons.gridx = 1;
		/* 230 */     cons.gridy = 1;
		/* 231 */     cons.gridwidth = 1;
		/* 232 */     cons.gridheight = 1;
		/* 233 */     cons.insets = new Insets(5, 0, 5, 5);
		cons.fill = 2;
		/* 234 */     this.jf2.setEditable(false);
		/* 235 */     upPanel.add(this.jf2, cons);
		
		/*     */	  cons = new GridBagConstraints();
		/* 227 */     cons.weightx = 0.0D;
		/* 228 */     cons.weighty = 0.0D;
		/* 229 */     cons.gridx = 1;
		/* 230 */     cons.gridy = 2;
		/* 231 */     cons.gridwidth = 1;
		/* 232 */     cons.gridheight = 1;
		/* 233 */     cons.insets = new Insets(5, 0, 5, 5);
		cons.fill = 2;
		/* 234 */     this.jf4.setEditable(false);
		/* 235 */     upPanel.add(this.jf4, cons); 
		
		/* 237 */     cons = new GridBagConstraints();
		/* 238 */     cons.weightx = 0.0D;
		/* 239 */     cons.weighty = 0.0D;
		/* 240 */     cons.gridx = 0;
		/* 241 */     cons.gridy = 3;
		/* 242 */     cons.gridwidth = 2;
		/* 243 */     cons.gridheight = 1;
		/* 244 */     cons.insets = new Insets(5, 10, 5, 5);
		/* 245 */     cons.fill = 0;
		/* 246 */     this.jf3.setEditable(false);
		/* 247 */     upPanel.add(this.jf3, cons);
		/*     */ 
		/* 249 */     cons = new GridBagConstraints();
		/* 250 */     cons.weightx = 0.0D;
		/* 251 */     cons.weighty = 0.0D;
		/* 252 */     cons.gridx = 0;
		/* 253 */     cons.gridy = 4;
		/* 254 */     cons.gridwidth = 2;
		/* 255 */     cons.gridheight = 1;
		/* 256 */     cons.insets = new Insets(5, 10, 5, 5);
		/* 257 */     cons.fill = 2;
		/* 258 */     upPanel.add(bar, cons);
	/*     */   }
/*     */ }

